﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PHMEE.PHM.Algorithms;
using PHMEE.TDengineInfrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Account;
using Volo.Abp.Application;
using Volo.Abp.AuditLogging;
using Volo.Abp.AutoMapper;
using Volo.Abp.EventBus.RabbitMq;
using Volo.Abp.FeatureManagement;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement;
using Volo.Abp.SettingManagement;
using Volo.Abp.TenantManagement;
using Magicodes.IE.Excel.Abp;
using PHMEE.Admin.Services.DataSync;

namespace PHMEE.Admin
{
    [DependsOn(
    typeof(PHMEEDomainModule),
    typeof(AbpAccountApplicationModule),
    typeof(AbpDddApplicationModule),
    typeof(PHMEEAdminApplicationContractsModule),
    typeof(AbpIdentityApplicationModule),
    typeof(AbpPermissionManagementApplicationModule),
    typeof(AbpTenantManagementApplicationModule),
    typeof(AbpFeatureManagementApplicationModule),
    typeof(AbpSettingManagementApplicationModule),
    typeof(AbpAuditLoggingDomainModule),
    typeof(MagicodesIEExcelModule),
    typeof(PHMEETDengineInfrastructureModule)
    )]
    public class PHMEEAdminApplicationModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            Configure<AbpAutoMapperOptions>(options =>
            {
                options.AddMaps<PHMEEAdminApplicationModule>();
            });
            
            var configuration = context.Services.GetConfiguration();
            bool isBoard = configuration.GetValue<bool>("IsBoard");
            if (isBoard)
            {
                // 如果是船端，则启动 Ship 数据同步服务
                context.Services.AddHostedService<DataSyncShipService>();
            }
            else
            {   
                // 如果是岸端，则启动 Shore 数据同步服务
                context.Services.AddHostedService<DataSyncShoreService>();
            }
        }
    }
}
